Table of Contents Previous Section

The awake Method

In an application or component script, it's common to implement an awake method that prepares the associated page and its variables for use during the processing of the page. For example, the Main.wos script in the Visitors application uses awake to increment the count of visitors to the page:

id number;
- awake {
  if (!number) {
    number = [WOApp visitorNum];
    number++;
    [WOApp setVisitorNum:number];
  }
  return self;
}  

For a given page, the awake method is invoked exactly once for each transaction. Therefore, if the same page handles the request as well as generates the response (for example, the first page of an application), the awake method is only invoked during the request phase.

The awake method is the best place to initialize variables whose values remain static for the life of the page, such as a list of hyperlinks. The advantage of using awake to perform this type of initialization is that the variables are guaranteed to be initialized every time the page is displayed.

Table of Contents Next Section